What is pluralize?
The pluralize npm package is a simple utility for converting words between their singular and plural forms. It can also handle irregular forms and uncountable nouns.
What are pluralize's main functionalities?
Pluralization
Converts a singular noun to its plural form, or vice versa, depending on the count provided. It also correctly handles uncountable nouns.
const pluralize = require('pluralize');
console.log(pluralize('fish')); // 'fish'
console.log(pluralize('fish', 5)); // 'fish'
console.log(pluralize('fish', 1)); // 'fish'
Singularization
Converts a plural noun to its singular form.
const pluralize = require('pluralize');
console.log(pluralize.singular('wolves')); // 'wolf'
Adding Irregular Rules
Allows the addition of custom irregular rules for nouns that do not follow the normal pluralization pattern.
const pluralize = require('pluralize');
pluralize.addIrregularRule('goose', 'geese');
console.log(pluralize('goose')); // 'geese'
Adding Uncountable Rules
Allows the addition of uncountable rules for nouns that should not be pluralized.
const pluralize = require('pluralize');
pluralize.addUncountableRule('equipment');
console.log(pluralize('equipment')); // 'equipment'
Other packages similar to pluralize
inflection
This package provides similar functionality to pluralize, including the ability to pluralize and singularize words. It also offers additional features like camelizing, underscore, humanize, etc. It is a more comprehensive solution for inflection than pluralize.
speakingurl
This package generates slugs from strings, which includes pluralization as part of its features. It is more focused on URL readability and SEO, whereas pluralize is solely dedicated to pluralization and singularization.
Pluralize
Pluralize and singularize any word.
Installation
npm install pluralize --save
bower install pluralize --save
Node
var pluralize = require('pluralize')
AMD
define(function (require, exports, module) {
var pluralize = require('pluralize')
})
<script>
tag
<script src="pluralize.js"></script>
Why?
This module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input. For applications where the word(s) are known ahead of time, you can use a simple ternary (or function) which would be a much lighter alternative.
Usage
pluralize('test')
pluralize('test', 1)
pluralize('test', 5)
pluralize('test', 1, true)
pluralize('test', 5, true)
pluralize.plural('regex')
pluralize.addPluralRule(/gex$/i, 'gexii')
pluralize.plural('regex')
pluralize.plural('singles', 1)
pluralize.addSingularRule(/singles$/i, 'singular')
pluralize.plural('singles', 1)
pluralize.plural('irregular')
pluralize.addIrregularRule('irregular', 'regular')
pluralize.plural('irregular')
pluralize.plural('paper')
pluralize.addUncountableRule('paper')
pluralize.plural('paper')
License
MIT